package com.action;

import java.io.InputStream;



import java.util.Date;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.common.uilt.BaseAction;
import com.common.uilt.DateUtil;
import com.service.imp.ReceiptService;
import com.service.imp.TreeService;

@Controller
@ParentPackage("defaultpackage")
@Namespace("/")
@Action(value = "downfile", results = {
		 @Result(name = "downaccets", type = "stream", params = {
					"contentType", "application/vnd.ms-excel", "inputName",
					"accetsinputStream", "contentDisposition",
					"attachment;filename=${downloadFileName}", "bufferSize", "4096" }) }

)
public class DownfileAction extends BaseAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 2036650898075841240L;
	private String downloadFileName;
	private String downloadFilepath;
	private InputStream accetsinputStream;
	private String data_month;
	@Autowired
	private TreeService treeService;
	@Autowired
	private ReceiptService receiptService;
	
	public String downaccetsclass(){
		try {
			this.downloadFileName="资产分类.xls";
			this.accetsinputStream=this.treeService.getAccetsclassDate();
		} catch (Exception e) {
			// TODO: handle exception
		}
		return "downaccets";
	}
	public String downDept(){
		try {
			this.downloadFileName="部门员工.xls";
			this.accetsinputStream=this.treeService.getDeptDate();
		} catch (Exception e) {
			// TODO: handle exception
		}
		return "downaccets";
	}
	public String downclassd(){
		try {
			if(null==data_month||"".equals(data_month)){
				data_month=DateUtil.SD3.format(new Date());
			}
			System.out.println(data_month);
			this.downloadFileName="资产折旧报表.xls";
			this.accetsinputStream=this.treeService.getDownd(receiptService.getreceiptcalss_dform(data_month),"ac_name");
		} catch (Exception e) {
			// TODO: handle exception
		}
		return "downaccets";
	}
	public String downdeptd(){
		try {
			if(null==data_month||"".equals(data_month)){
				data_month=DateUtil.SD3.format(new Date());
			}
			this.downloadFileName="部门资产折旧报表.xls";
			this.accetsinputStream=this.treeService.getDownd(receiptService.getreceiptdept_dform(data_month),"dept_name");
		} catch (Exception e) {
			// TODO: handle exception
		}
		return "downaccets";
	}
	public String downdeptThree(){
		try {
			if(null==data_month||"".equals(data_month)){
				data_month=DateUtil.SD3.format(new Date());
			}
			this.downloadFileName="部门资产三栏账.xls";
			this.accetsinputStream=this.treeService.getDowndeptThree(receiptService.getReceiptdeptThreeForm(data_month));
		} catch (Exception e) {
			// TODO: handle exception
		}
		return "downaccets";
	}
	public InputStream getAccetsinputStream() throws Exception{
		return this.accetsinputStream;
	}
	
	public void setAccetsinputStream(InputStream accetsinputStream) {
		this.accetsinputStream = accetsinputStream;
	}
	
	public String getDownloadFileName() {
		String encode_filename = "";
		if (this.downloadFileName != null && !this.downloadFileName.equals("")) {
			try {
				encode_filename = new String(this.downloadFileName
						.getBytes("GBK"), "ISO-8859-1");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return encode_filename;
	}
	public void setDownloadFileName(String downloadFileName) {
		this.downloadFileName = downloadFileName;
	}
	public String getDownloadFilepath() {
		return downloadFilepath;
	}
	public void setDownloadFilepath(String downloadFilepath) {
		this.downloadFilepath = downloadFilepath;
	}
	public String getData_month() {
		return data_month;
	}
	public void setData_month(String data_month) {
		this.data_month = data_month;
	}
	
	
}
